package com.bluefish.bltuan.action.user;

import java.util.List;

import org.apache.struts2.rest.DefaultHttpHeaders;
import org.apache.struts2.rest.HttpHeaders;

import com.bluefish.bltuan.action.OpenAction;
import com.bluefish.bltuan.module.Category;
import com.bluefish.bltuan.module.user.Businesser;
import com.bluefish.bltuan.service.BusinesserService;
import com.bluefish.bltuan.service.CategoryService;
import com.bluefish.bltuan.tools.ActionUtil;

/**
 * @author blue
 * 商家登记Action
 * 
 */
public class BusinesserAction extends OpenAction {

	private static final long serialVersionUID = -371566045138381419L;
	
	private Businesser businesser;
	
	private BusinesserService businesserService;
	
	private CategoryService categoryService;

	public void setBusinesserService(BusinesserService businesserService) {
		this.businesserService = businesserService;
	}

	public Businesser getBusinesser() {
		return businesser;
	}

	public void setBusinesser(Businesser businesser) {
		this.businesser = businesser;
	}
	
	@Override
	public HttpHeaders index() {
		return null;
	}

	@Override
	public HttpHeaders show() {
		return null;
	}

	@Override
	public String update() {
		return null;
	}

	@Override
	public String edit() {
		return null;
	}

	@Override
	public String destroy() {
		return null;
	}

	@Override
	public HttpHeaders create() {
		String cityId = ActionUtil.getRequestParameter("cityId");
		String styleId = ActionUtil.getRequestParameter("styleId");
		Category city = this.categoryService.findById(Integer.valueOf(cityId));
		Category style = this.categoryService.findById(Integer.valueOf(styleId));
		this.businesser.setCity(city);
		this.businesser.setStyle(style);
		this.businesserService.save(this.businesser);
		return new DefaultHttpHeaders(SUCCESS).disableCaching();
	}

	@Override
	public HttpHeaders editNew() {
		return new DefaultHttpHeaders(NEW).disableCaching();
	}
	
	public List<Category> getStyles(){
		return this.categoryService.listCategoryByType(CategoryService.TUANGOU);
	}
	
	public void setCategoryService(CategoryService categoryService) {
		this.categoryService = categoryService;
	}
 
}